<template>
  <el-container>
    <el-header>
      <div style="width:200px;font-size: 1.6rem">同学圈分享平台</div>
      <el-menu
              :default-active="activeIndex2"
              class="el-menu-header-nav"
              mode="horizontal"
              @select="handleSelect"
              background-color="#23262E"
              text-color="#fff"
              active-text-color="#ffd04b">
        <el-menu-item index="1">处理中心</el-menu-item>
        <el-submenu class="navHeader" index="2">
          <template slot="title">我的工作台</template>
          <el-menu-item index="2-1">选项1</el-menu-item>
          <el-menu-item index="2-2">选项2</el-menu-item>
          <el-menu-item index="2-3">选项3</el-menu-item>
          <el-submenu index="2-4">
            <template slot="title">选项4</template>
            <el-menu-item index="2-4-1">选项1</el-menu-item>
            <el-menu-item index="2-4-2">选项2</el-menu-item>
            <el-menu-item index="2-4-3">选项3</el-menu-item>
          </el-submenu>
        </el-submenu>
        <el-menu-item index="3" disabled>消息中心</el-menu-item>
        <el-menu-item index="4">订单管理</el-menu-item>
      </el-menu>
      <div class="caozuo">
        <el-avatar :size="40" :src="user.userImg"></el-avatar>
        <el-dropdown>
          <span class="el-dropdown-link">
            {{user.userName}}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>基本资料</el-dropdown-item>
            <el-dropdown-item>安全设置</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <div><router-link to="/login">退出</router-link></div>
      </div>
    </el-header>
    <el-container :style="container">
      <el-aside width="20rem">
        <leftNav/>
      </el-aside>
      <el-container>
        <el-main>
          <el-breadcrumb class="app-breadcrumb" separator-class="el-icon-arrow-right">
            <el-breadcrumb-item v-for="(item)  in levelList" :key="item.path" v-if="item.meta.title">
              <router-link :to="item.redirect||item.path">{{item.meta.title}}</router-link>
            </el-breadcrumb-item>
          </el-breadcrumb>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </el-container>
</template>

<script>

import leftNav from '../components/LeftNav'
import {mapState} from 'vuex'
export default {
  name: 'Home',
  computed:{
    ...mapState(['user'])
  },
  data(){
    return{
      container:{
        height: document.documentElement.clientHeight - 60 + 'px'
      },
      levelList:null,
      activeIndex: '1',
      activeIndex2: '1'
    }
  },
  methods:{
    getBreadcrumb() {
      let matched = this.$route.matched.filter(item => item.name)
      const first = matched[0]
      if (first && first.name !== '首页') {
        matched = [{path: '/home', meta: { title: '首页' }}].concat(matched)
      }
      this.levelList = matched;
    },
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    }
  },
  mounted() {
    this.getBreadcrumb();
  },
  watch: {
    $route(to, from) {
      this.getBreadcrumb();
    }
  },
  components: {
    leftNav
  }
}
</script>
<!--页头页脚的样式在这里修改-->
<style lang="less">
  .el-header, .el-footer {
    background-color: #23262E;
    color: #BDBEC1;
    text-align: center;
    line-height: 60px;
  }
  .caozuo{
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.6rem;
  }
  .caozuo .el-avatar{
    display: inline-block;
  }
  .el-menu-header-nav{
    flex-grow:1;
  }
  .el-header{
    display: flex;
    justify-content: space-between;
  }
  .el-aside {
    color: #333;
    width: 20rem;
    text-align: center;
    line-height: 200px;
    background-color: #545C64;
  }
  .el-main {
    color: #333;
    text-align: center;
    line-height: 160px;
  }
  .el-breadcrumb{
    border-bottom: 1px solid black;
    padding: 1.2rem 0;
  }
  .el-dropdown{
    margin: 0 3rem 0 1.5rem;
    cursor: pointer;
  }
  .el-menu.el-menu--horizontal{
    border-bottom: none!important;
  }
</style>
